﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;


namespace WebSite.Ajax
{
    public partial class UserCareAjax : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string objectid = Request.QueryString["objectid"] + "";
            string objecttype = Request.QueryString["objecttype"] + "";
            Users uinfo = UserBase.GetCurrentUser();
            if (uinfo == null)
            {
                Response.Write("请先登录");
                return;
            }
            else
            {
                //判断是否已经关注过
                UserCareHelper uchelper = new UserCareHelper();
                Criteria c = new Criteria();
                c.Add(CriteriaType.Equals, "UsersID", uinfo.ID);
                c.Add(CriteriaType.Equals, "ObjectID", objectid);
                c.Add(CriteriaType.Equals, "ObjectType", objecttype);
                int count = uchelper.QueryUserCareCountBySearch(c);
                if (count > 0)
                {
                    Response.Write("已经关注过");
                    return;
                }
                else
                {
                    //增加关注记录
                    UserCare ucinfo = new UserCare();
                    ucinfo.UsersID = uinfo.ID;
                    ucinfo.ObjectID = objectid;
                    ucinfo.ObjectType =Convert.ToInt32( objecttype);
                    uchelper.AddUserCare(ucinfo);

                    //增加小组的关注个数
                    if (objecttype == "1")
                    {
                        Companys cinfo = new Companys();
                        CompanysHelper chelper = new CompanysHelper();
                        cinfo = chelper.GetCompanys(objectid);
                        int carenum = cinfo.CareNum;
                        carenum = carenum + 1;
                        cinfo.CareNum = carenum;
                        chelper.EditCompanys(cinfo);
                    }

                    Response.Write("关注成功");
                    return;
                }
            }
        }
    }
}